home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.002.BusyBox / busybox.c / uevent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-19  |  3.1 KB  |  133 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * busybox uevent.c -- Version 3.0
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1990
  7. * All Rights Reserved.
  8. *
  9. * This file contains the code which implements the
  10. * main event loop used by the busybox program.
  11. *
  12. **********************************************************************/
  13.  
  14. #include <types.h>
  15. #include <locator.h>
  16. #include <quickdraw.h>
  17. #include <event.h>
  18. #include <menu.h>
  19. #include <window.h>
  20. #include "busybox.h"
  21.  
  22. extern WmTaskRec        event;
  23. extern unsigned int     quitFlag;
  24.  
  25. static GrafPortPtr    lastWindow;         /* This private global is used in checkFrontW()
  26.                                         ** to prevent extra work when the windows
  27.                                         ** have not changed.  It is initialized
  28.                                         ** at the beginning of mainEvent().
  29.                                         */
  30.  
  31. /**********************************************************************
  32. *
  33. * doControls
  34. *
  35. * This procedure is called when an inControl message is returned
  36. * by TaskMaster.
  37. *
  38. * When this routine gets control, the ID of the control that was
  39. * hit is in TaskDATA4.    The control handle is in TaskData2 and
  40. * the part code is in taskData 3.
  41. *
  42. **********************************************************************/
  43. void    doControls()
  44. {
  45.     unsigned int    theID;
  46.  
  47.     theID = event.wmTaskData4;
  48.  
  49.     if ((ButButtonsID <= theID) && (theID <= Prog6ID)) {
  50.         openThisWindow(theID);
  51.     }
  52. }
  53.  
  54.  
  55.  
  56. /**********************************************************************
  57. *
  58. * checkFrontW
  59. *
  60. * This routine checks the front window to see if any changes need
  61. * to be made to the menu items.
  62. *
  63. * We do this so that the edit items are only active when a desk
  64. * accessory is active.
  65. *
  66. **********************************************************************/
  67. void    checkFrontW()
  68. {
  69.     GrafPortPtr     theWindow;
  70.  
  71.     theWindow = FrontWindow();
  72.         /* Get the front window into local storage.*/
  73.     
  74.     if (theWindow == lastWindow) return;
  75.         /* If the lastWindow is this window, we are all set. */
  76.     
  77.     /* If there are no windows, everything should be disabled */
  78.     if (!theWindow) {
  79.         SetMenuFlag(0x0080, EditMenuID);
  80.         DrawMenuBar();
  81.     }
  82.     else {
  83.         /* Otherwise we look at the window and see what to do. */
  84.         if (GetSysWFlag(theWindow)) {
  85.             SetMenuFlag (0xFF7F, EditMenuID);        /* Set up for da windows. */
  86.             DrawMenuBar();
  87.         }
  88.         else {
  89.             SetMenuFlag (0x0080, EditMenuID);        /* Set up for our windows. */
  90.             DrawMenuBar();
  91.         }
  92.     }
  93.  
  94.     lastWindow = theWindow;     /* Remember this for next time. */
  95. }
  96.  
  97.  
  98.  
  99. /**********************************************************************
  100. *
  101. * mainEvent
  102. *
  103. * This is the main part of the program.  The program cycles in this
  104. * loop until the user choose select.
  105. *
  106. **********************************************************************/
  107. void    mainEvent()
  108. {
  109.     unsigned int    code;
  110.  
  111.     event.wmTaskMask = 0x001FFFFF;            /* Allow TaskMaster to do everything.    */
  112.     quitFlag         = 0;                    /* Done flag will be set by Quit item.    */
  113.     lastWindow         = NULL;                /* Init this for checkFrontW().         */
  114.  
  115.     for (;;) {
  116.         checkFrontW();
  117.         code = TaskMaster(0xFFFF, &event);
  118.         switch(code) {
  119.             case wInGoAway:
  120.                 doCloseTop();
  121.                 break;
  122.             case wInSpecial:
  123.             case wInMenuBar:
  124.                 doMenu();
  125.                 break;
  126.             case wInControl:
  127.                 doControls();
  128.                 break;
  129.         }
  130.         if (quitFlag) break;
  131.     }
  132. }
  133.